package com.huawei.hms.framework.network.restclient.hwhttp.okhttp;

import com.huawei.hms.framework.network.restclient.hwhttp.route.IPRoute;
import java.util.concurrent.TimeUnit;
import o.fuf;
import o.ful;
import o.fun;
import o.fut;
import o.fuv;
import o.fuv.b;
import o.fvg;

public class OkHttpClientGlobal {
    private static final int DEFAULT_CONNECTION_KEEPALIVE_DURATION = 5;
    private static final int DEFAULT_CONNECTION_SIZE = 8;
    private static final TimeUnit DEFAULT_CONNECTION_TIMEUNIT = TimeUnit.MINUTES;
    private static OkHttpClientGlobal INSTANCE = null;
    private static final int MAX_HTTP2_REQUEST_PER_HOST = 32;
    private static final int MAX_REQUEST_SIZE = 200;
    private fuv client;
    private long connectionKeepAliveDuration;
    private TimeUnit connectionTimeUnit;
    private int maxIdleConnections;

    private OkHttpClientGlobal() {
        this(8, 5, DEFAULT_CONNECTION_TIMEUNIT);
    }

    private OkHttpClientGlobal(int i, long j, TimeUnit timeUnit) {
        this.maxIdleConnections = 8;
        this.maxIdleConnections = i;
        this.connectionKeepAliveDuration = j;
        this.connectionTimeUnit = timeUnit;
    }

    public static synchronized OkHttpClientGlobal getInstance() {
        OkHttpClientGlobal okHttpClientGlobal;
        synchronized (OkHttpClientGlobal.class) {
            if (INSTANCE == null) {
                INSTANCE = new OkHttpClientGlobal();
            }
            okHttpClientGlobal = INSTANCE;
        }
        return okHttpClientGlobal;
    }

    public static synchronized void init(int i, long j, TimeUnit timeUnit) {
        synchronized (OkHttpClientGlobal.class) {
            if (INSTANCE == null) {
                INSTANCE = new OkHttpClientGlobal(i, j, timeUnit);
            }
        }
    }

    public synchronized fuv getClient() {
        if (this.client == null) {
            ful o_fun = new fun();
            o_fun.ˋ(MAX_REQUEST_SIZE);
            o_fun.ˊ(32);
            this.client = new b().ˊ(new fuf(this.maxIdleConnections, this.connectionKeepAliveDuration, this.connectionTimeUnit)).ˎ(o_fun).ॱ(fvg.ˋ(new fut[]{fut.ˊ, fut.ˋ})).ॱ((long) IPRoute.getInstance().getChainInterval(), TimeUnit.MILLISECONDS).ˋ(HttpEventListener.getFactory()).ˋ();
        }
        return this.client;
    }

    public int getMaxIdleConnections() {
        return this.maxIdleConnections;
    }

    public long getConnectionKeepAliveDuration() {
        return this.connectionKeepAliveDuration;
    }

    public TimeUnit getConnectionTimeUnit() {
        return this.connectionTimeUnit;
    }
}
